package com.hongxun.project.assets.iDevice.controller;

import java.util.List;

import com.hongxun.project.assets.iPoint.domain.IPoint;
import com.hongxun.project.assets.iPoint.service.IIPointService;
import com.hongxun.project.assets.pPoint.domain.PPoint;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.iDevice.domain.IDevice;
import com.hongxun.project.assets.iDevice.service.IIDeviceService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 配电设备基类 信息操作处理
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Controller
@RequestMapping("/assets/iDevice")
public class IDeviceController extends BaseController
{
    private String prefix = "assets/iDevice";
	
	@Autowired
	private IIDeviceService iDeviceService;
	@Autowired
	private IIPointService iPointService;



	
//	@RequiresPermissions("assets:iDevice:view")
	@GetMapping()
	public String iDevice(IDevice iDevice , ModelMap modelMap)
	{
		String pointId = iDevice.getPointId();

		IPoint pPoint = iPointService.selectIPointById(pointId);
		modelMap.put("lineId", pPoint.getLineId());    // 线路ID
		modelMap.put("byqId", pPoint.getByqId());    // 变压器ID
		modelMap.put("pointId", pointId);                    // 点位ID
	    return prefix + "/iDevice";
	}
	
	/**
	 * 查询配电设备基类列表
	 */
//	@RequiresPermissions("assets:iDevice:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IDevice iDevice)
	{
		startPage();
        List<IDevice> list = iDeviceService.selectIDeviceList(iDevice);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出配电设备基类列表
	 */
	@RequiresPermissions("assets:iDevice:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IDevice iDevice)
    {
    	List<IDevice> list = iDeviceService.selectIDeviceList(iDevice);
        ExcelUtil<IDevice> util = new ExcelUtil<IDevice>(IDevice.class);
        return util.exportExcel(list, "iDevice");
    }
	
	/**
	 * 新增配电设备基类
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存配电设备基类
	 */
	@RequiresPermissions("assets:iDevice:add")
	@Log(title = "配电设备基类", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IDevice iDevice)
	{		
		return toAjax(iDeviceService.insertIDevice(iDevice));
	}

	/**
	 * 修改配电设备基类
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		IDevice iDevice = iDeviceService.selectIDeviceById(id);
		mmap.put("iDevice", iDevice);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存配电设备基类
	 */
	@RequiresPermissions("assets:iDevice:edit")
	@Log(title = "配电设备基类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IDevice iDevice)
	{		
		return toAjax(iDeviceService.updateIDevice(iDevice));
	}
	
	/**
	 * 删除配电设备基类
	 */
	@RequiresPermissions("assets:iDevice:remove")
	@Log(title = "配电设备基类", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(iDeviceService.deleteIDeviceByIds(ids));
	}
	
}
